<%@page import="com.wowangz.cms.common.utils.MessageObject"%>
<%@page import="com.wowangz.cms.common.utils.DictTypeConstant"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/pageHead.jsp"%>
<link rel="stylesheet" href="${systemctx}/resources/webuploader/webuploader.css">
<link rel="stylesheet" href="${systemctx}/resources/css/fileupload.css">

<script type="text/javascript" src="${systemctx}/resources/webuploader/webuploader.js" charset="UTF-8" ></script>
<script type="text/javascript" src="${systemctx}/resources/js/jquery.validation.js" charset="UTF-8" ></script>

<c:set value="<%=SysConstant.CommonApproveStatus.SAVED %>" var="state"></c:set>
<c:set value="<%=SysConstant.CommonApproveStatus.REFUSED %>" var="refuse"></c:set>
<script type="text/javascript">
	$(document).ready(function() {
		/* var width = document.body.clientWidth;
		$("#description").css("width",width*0.68+"px"); */
		$("#quality").selectutil({
			optModel : <%=DictTypeConstant.getDataDictionaryInfoSelectList(DictTypeConstant.QUALITY,false,false)%>,
			optDefault :'${store.quality}'
		});
		$("#industry").selectutil({
			optModel : <%=DictTypeConstant.getDataDictionaryInfoSelectList(DictTypeConstant.STOREINDUSTRY,false,false)%>,
			optDefault :'${store.industry}'
		});
		$("#population").selectutil({
			optModel : <%=DictTypeConstant.getDataDictionaryInfoSelectList(DictTypeConstant.POPULATION,false,false)%>,
			optDefault :'${store.population}'
		});
		$("#butReturn").click(function(){
			parent.document.location.reload();
		    $.fn.closeIssWindow();
		});
		selectCityByProvinceId();
	});
	
	function businesslicenseUplaod(){
		$("#fileupload").click();
	}
	
	/*flag == 1 表示保存，flag == 2 表示提交*/
	function save(flag){
		var exp = $('#form1').validationEngine('validate');
		if(exp==true){
			var businesslicenseid = $("#businesslicenseid").val();
			if(businesslicenseid == '') {
				alert("请上传营业执照扫描件.");
				return;
			}
			window.setTimeout(function(){ 
				var isSubmit = $("#isSubmit").val();
				if(isSubmit == 1) {
					return;
				}
				// 显示进度条
				showSending();
				$.ajax({
					type : 'POST',
					url : '${systemctx}/dailyoperation/store/queryStoreInfoNumber.json',
					data : $("#form1").serialize(),
					dataType : 'json',
					success : function(data) {
						//关闭执行...
						closeSending();
						if (data.code == true) {
							alert(data.message);
							return ;
						} else {
							// 显示进度条
							showSending();
							$.ajax({
								type: 'POST',
							    url: '${systemctx}/dailyoperation/store/updateStoreInfo.web?flag='+flag,
							    data: $("#form1").serialize(),
							    dataType: 'json',
							    success: function(data) {
							    	//关闭执行...
									closeSending();
							    	if(data.code == 200){
							    		alert(data.message);
							    		window.location.href='${systemctx}/dailyoperation/store/manageList.web';
							    	}else {
							    		alert(data.message);
							    		return;
							    	}
							    }
							});
						}
					}
				});
			},200);
		}
	}
	
	function selectCityByProvinceId() {
		var provinceid = $("#provinceid").val();
		var value = '<%=MessageResourcesUtils.getMessage(request, "common.select.all")%>';
		/* var str = '<option value="">'+value+'</option>'; */
		var str = '';
		if(provinceid != "" && provinceid != undefined){
			$.getJSON('${systemctx}/dailyoperation/store/getCityJson.json?id='+provinceid,function(data){
				for(var i = 0;i < data.length; i++){
					if(data[i].id=='${store.cityid}'){
						str += "<option value=\""+data[i].id+"\" selected=\"selected\">"+data[i].cityname+"</option>";
					}else {
						str += "<option value=\""+data[i].id+"\">"+data[i].cityname+"</option>";
					}
				}
				$("#cityid").html(str);
			});
		}
	}
	
	$(document).ready(function (){
		$(".website").validation({
			url: '${systemctx}/dailyoperation/store/validationWebSite.json',//上传的地址
            submitBtns : ['butSave','butSubmit'],
            id : '${store.id}',
            defaultMsg:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.website.alert") %>',
 			errorMsg : '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.website.alert2")%>'
		});
		
		var show = '<div id="show">'
	        + '<div class="dialog-title">'
	        + '提示信息'
	        + '<a id="showClose" href="javascript:hidediv()" class="dialog-close">关闭</a>'
	        + '</div>'
	        + '<div id="showText" class="dialog-content">'
	        + '正在上传，请稍等...'
	        + '</div>'
	        + '</div>';
	    var bg = '<div id="bg"></div>';
	    $("body").append(bg).append(show);
		var uploader = WebUploader.create({
		    // swf文件路径
		    swf: '${systemctx}/resources/webuploader/Uploader.swf',
		    // 文件接收服务端。
		    server: '${systemctx}/dailyoperation/store/attachment/copy.web',
		    // 选择文件的按钮。可选。
		    // 内部根据当前运行是创建，可能是input元素，也可能是flash.
		    pick: {
		    	id : '#picker',
		    	multiple : false
		    },
		    auto : true,
		    // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
		    resize: false
		});
		// 当有文件被添加进队列的时候
		uploader.on( 'fileQueued', function( file ) {
			$list = $("#thelist");
		    $list.html( '<div id="' + file.id + '" class="item">' +
		        '<h4 class="info"><a id="downloadHref">' + file.name + '</a></h4>' +
		        '<p class="state">等待上传...</p>' +
		    '</div>' );
		});
		// 文件上传过程中创建进度条实时显示。
		uploader.on( 'uploadProgress', function( file, percentage ) {
		    var $li = $( '#'+file.id ),
		        $percent = $li.find('.progress .progress-bar');
		    // 避免重复创建
		    if ( !$percent.length ) {
		        $percent = $('<div class="progress progress-striped active">' +
		          '<div class="progress-bar" role="progressbar" style="width: 0%">' +
		          '</div>' +
		        '</div>').appendTo( $li ).find('.progress-bar');
		    }
		    /* $li.find('p.state').text('上传中'); */
		    showdiv();
		    $percent.css( 'width', percentage * 100 + '%' );
		});
		uploader.on( 'uploadSuccess', function( file ,response) {
			if(response.resposecode == '<%=MessageObject.ResponseCode.code_200%>') {
		    	$( '#showText').text('<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.website.alert8")%>.');
		    	$("#businesslicenseid").val(response.object[0].id);
		    	$("#downloadHref").attr("href","${systemctx}/dailyoperation/store/attachment/download.json?id=" + response.object[0].id);
				window.setTimeout(function(){ 
					hidediv();
			    	$( '#'+file.id ).find('p.state').text('<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.website.alert8")%>');
				},1000);
			} else {
				$( '#showText').text(response.message);
				window.setTimeout(function(){ 
					hidediv();
			    	$( '#'+file.id ).find('p.state').html("<span style='color:red'>"+response.message+"</span>");
				},1000);
			}
		});
		uploader.on( 'uploadError', function( file ) {
			hidediv();
		    $( '#'+file.id ).find('p.state').text('上传出错');
		});
		uploader.on( 'uploadComplete', function( file ) {
		    $( '#'+file.id ).find('.progress').fadeOut();
		});
	});
	
	function showdiv() {
	    document.getElementById("bg").style.display = "block";
	    document.getElementById("show").style.display = "block";
	}
	function hidediv() {
	    document.getElementById("bg").style.display = 'none';
	    document.getElementById("show").style.display = 'none';
	}
</script>
<style type="text/css">
	.webuploader-pick {
	    padding: 0px 5px;
	}
	#picker {
		float:left;
	}
	#thelist {
		float:left;
		margin-left: 20px;
	}
</style>
<form name="form1" id="form1" action="" method="post">
	<div class="pageMain">
		<div class="pageTitle">
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.storemanagement.title")%>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.register.title")%>
			<span></span>
			<c:if test="${store.id != '' && store.id != null && not empty store.id}">
				<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.edit") %>
			</c:if>
			<c:if test="${empty store.id}">
				<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.add") %>
			</c:if>
			
		</div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li class="paymentHeadStyle liw">
						<i></i>
						<label>
							<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.register.info") %>
						</label>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.number") %>
						</label>
						<span>
							<input type="hidden" value="${store.id}" id="id" name="id" />		
							<input type="hidden" value="${number}" id="number" name="number" />		
							<input type="text" value="${number}" disabled="disabled" size="22" class="validate[required,maxSize[20]]" />
						</span>
					</li>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.name") %>
						</label>
						<span><input type="text" id="name" value="${store.name}" name="name" maxlength="100" size="100" class="validate[required,maxSize[90]]" /></span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.corporate") %>
						</label>
						<span><input type="text" id="corporate" value="${store.corporate}" name="corporate" class="validate[required,maxSize[20]]" /></span>		
					</li>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.quality") %>
						</label>
						<span><select name="quality" id="quality" class="validate[required]"></select></span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.population") %>
						</label>
						<span><select id="population" name="population" class="validate[required]"></select></span>		
					</li>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.pCity") %>
						</label>
						<span>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.provinceid") %>
							<select id="provinceid" name="provinceid" onchange="selectCityByProvinceId()" style="width:120px;" class="validate[required]">
								<option value="">
									<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.select.option") %>
								</option>
								<c:forEach items="${provinces}" var="p">
									<option value="${p.id}" <c:if test="${p.id==store.provinceid}">selected="selected"</c:if> >${p.provincename}</option>
								</c:forEach>
							</select>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.cityid") %>
							<select id="cityid" name="cityid" style="width:120px;" class="validate[required]">
								<option value="">
									<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.select.city") %>
								</option>
							</select>
						</span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.industry") %>
						</label>
						<span><select id="industry" name="industry"></select></span>	
					</li>
					<li>
						<i>*</i>
						<label>
							<!-- 营业执照号码 -->
							<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.businesslicensecode") %>
						</label>
						<span>
							<input type="text" class="validate[required,maxSize[100]]" value="${store.businesslicensecode}" name="businesslicensecode" id="businesslicensecode"/>
						</span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label>
							<!-- 机构代码证号码 -->
							<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.organizationcode") %>
						</label>
						<span>
							<input name="organizationcode" class="validate[required,maxSize[100]]" value="${store.organizationcode}" type="text" id="organizationcode"/>
						</span>
					</li>
					<li>
						<i>*</i>
						<label>
							<!-- 税务登记证号码 -->
							<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.certificatecode") %>
						</label>
						<span>
							<input type="text" class="validate[required,maxSize[100]]" value="${store.certificatecode}" name="certificatecode" id="certificatecode" />
						</span>
					</li>
				</ul>
				<ul>
					<li class="liw">
						<i>*</i>
						<label>
							<!-- 营业执照扫描件上传 -->
							<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.businesslicenseid") %>
						</label>
						<span>
							<div id="uploader" class="wu-example">
								<div id="picker">
						        	<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.upload") %>
						        </div>
							    <!--用来存放文件信息-->
							    <div id="thelist" class="uploader-list">
							    	<div id="${store.businesslicenseid}" class="item">
							        	<h4 class="info">
							        		<a id="downloadHref" href="${systemctx}/dailyoperation/store/attachment/download.json?id=${store.businesslicenseid}">${attachment.name}</a>
							        	</h4>
							    	</div>
							    </div>
						    </div>
							<span id="filename">
								<input type="hidden" value="${attachment.id}" name="businesslicenseid" id="businesslicenseid">
							</span>
						</span>
					</li>
				</ul>
				<ul>
					<li class="liw">
						<i></i>
						<label>
							<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.website") %>
						</label>
						<span>
							${store.website }
						</span>
					</li>
				</ul>
				<ul>
					<li style="height:80px;width: 100%">
						<i></i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.description") %>
						</label>
						<span><textarea rows="" cols="" class="validate[maxSize[900]]" id="description" name="description" style="width:600px;height:80px;">${store.description}</textarea></span>
					</li>
				</ul>
				<ul>
					<li class="paymentHeadStyle liw">
						<i></i>
						<label>
							<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.contacts.info") %>
						</label>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.realname") %>
						</label>
						<span><input type="text" id="realname" name="realname" value="${store.realname}" maxlength="20" size="20" class="validate[required,maxSize[20]]" /></span>		
					</li>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.telephonenumber") %>
						</label>
						<span><input type="text" id="telephonenumber"  size="20" maxlength="20" value="${store.telephonenumber}" name="telephonenumber" maxlength="22" size="22" class="validate[required,custom[mobile],maxSize[20]]" /></span>		
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.email") %>
						</label>
						<span><input type="text" id="email" name="email" value="${store.email}" maxlength="30" size="30" class="validate[required,custom[email],maxSize[30]]" /></span>		
					</li>
					<li>
						<i></i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.phonenumber") %>
						</label>
						<span><input type="text" id="phonenumber" value="${store.phonenumber}" name="phonenumber" maxlength="22" size="22" class="validate[custom[phonenumber],maxSize[20]]" /></span>		
					</li>
				</ul>
			</div>
			<div class="button-group">
				<input type="button" class="btn btn-default" id="butSave" onclick="save('1')" name="butSave"  value='<%=MessageResourcesUtils.getMessage(request, "common.button.update") %>' />
				<input type="button" class="btn btn-default" id="butReturn" name="butReturn" value='<%=MessageResourcesUtils.getMessage(request, "common.button.back") %>' />
			</div>
		</div>
	</div>
</form>

<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>